package com.example.city_home_app.Activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.Window;
import android.view.WindowManager;

import com.example.city_home_app.Bean.Down_Login;
import com.example.city_home_app.R;

public  abstract class BaseActivity extends AppCompatActivity {

    private static Down_Login userinfo;

    public static Down_Login getUserinfo() {
        return userinfo;
    }

    public static void setUserinfo(Down_Login userinfo) {
        BaseActivity.userinfo = userinfo;
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        //隐藏状态栏
        supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
        if (initArgs(getIntent().getExtras())) {
            int layoutId = getContentLayoutId();
            if (layoutId == R.layout.activity_init||layoutId == R.layout.activity_login||layoutId == R.layout.activity_reg||layoutId == R.layout.activity_forgot||layoutId == R.layout.activity_moment_info
            ||layoutId == R.layout.activity_photo||layoutId == R.layout.activity_video||layoutId == R.layout.activity_userinfo) {
                getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                        WindowManager.LayoutParams.FLAG_FULLSCREEN);
            }
            setContentView(layoutId);
            initViews();
            initData();
        } else {
            finish();
        }
    }

    protected abstract int getContentLayoutId();

    /**
     * 初始化参数
     *
     * @param bundle 需要初始化的参数
     * @return 如果参数正确返回true, 错误返回false
     */
    protected boolean initArgs(Bundle bundle) {
        return true;
    }

    /**
     * 初始化窗口
     */
    protected void initViews() {

    }

    /**
     * 初始化数据
     */
    protected void initData() {

    }

    @Override
    public boolean onSupportNavigateUp() {
        //当点击界面导航返回时,finish当前界面
        finish();
        return super.onSupportNavigateUp();
    }
}
